// 店铺数据
const memoryStorage = {
  '1001': { name: '良品铺子' },
  '1002': { name: '来伊份' },
  '1003': { name: '三只松鼠' },
  '1004': { name: '百草味' },
};

class TestService {
  async find({ id, pageIndex = 0, pageSize = 10 }) {
    if (id) {
      return [memoryStorage[id]].filter(Boolean);
    }
    return Object.keys(memoryStorage)
        .slice(pageIndex * pageSize, (pageIndex + 1) * pageSize)
        .map((id) => ({ id, ...memoryStorage[id] }));
  }
}

// 单例模式
let service;
module.exports = async function() {
  if (!service) {
    service = new TestService();
  }
  return service;
}